package com.alter.prouducer.producer;

import com.alter.prouducer.entity.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by hucong on 2019/6/9.
 */
@Component
public class OrderSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(Order order){

        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(order.getId());

        /**
         * 还要在 rabbitmq 控制台配置exchange和queue，并绑定
         * 加绑定在控制台的exchange和queues哪一块都可以
         */
        rabbitTemplate.convertAndSend("order-exchange", //exchange
                "order.abcd", //routingKey
                order,                  //消息体内容
                correlationData);       //消息唯一ID
    }

}
